package com.zz.ecommerce.declareManage.common.dao;

import com.zz.ecommerce.common.CommonDao;
import com.zz.ecommerce.common.bean.qdc.db.LogisticsOrderQdc;
import com.zz.ecommerce.common.bean.qdc.db.TOrderHeadQdc;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2015-12-15.
 */
@Repository
public interface QdcOrderHeadDao extends CommonDao<TOrderHeadQdc> {
    //yourself method

    @Select("SELECT COUNT(1) FROM T_ORDER_HEAD_QDC " +
            "        join T_Waybill_List_Qdc " +
            "         on T_ORDER_HEAD_QDC.id = T_Waybill_List_Qdc.releated_id " +
            "        join T_Waybill_Head_Qdc " +
            "         on T_Waybill_List_Qdc.logi_ente_code = " +
            "            T_Waybill_Head_Qdc.logi_ente_code " +
            "        and T_Waybill_List_Qdc.waybill_Id = " +
            "            T_Waybill_Head_Qdc.waybill_Id WHERE ${condition}")
    int countOrderEq(@Param("condition") String condition);

    @Select("SELECT  ID," +
            "       ORDER_ID," +
            "       IE_FLAG," +
            "       TRADE_MODE," +
            "       EB_CODE," +
            "       EB_NAME," +
            "       TOTAL_PAYMENT," +
            "       CURR_CODE," +
            "       BUYER_NAME," +
            "       BUYER_CERT_TYPE," +
            "       BUYER_CERT_ID," +
            "       BUYER_COUNTRY," +
            "       BUYER_TEL," +
            "       DELIVERY_ADDR," +
            "       EB_PLAT_ID," +
            "       NOTE," +
            "       TO_CHAR(CREATE_TIME,'YYYY-MM-DD') AS CREATE_TIME," +
            "       STATUS,WAYBILL_ID" +
            "  FROM (SELECT A.*, ROWNUM RN" +
            "          FROM (SELECT T_ORDER_HEAD_QDC.*, T_Waybill_Head_Qdc.WAYBILL_ID\n" +
            "    FROM T_ORDER_HEAD_QDC\n" +
            "     join T_Waybill_List_Qdc\n" +
            "      on T_ORDER_HEAD_QDC.id = T_Waybill_List_Qdc.releated_id\n" +
            "     join T_Waybill_Head_Qdc\n" +
            "      on T_Waybill_List_Qdc.logi_ente_code =\n" +
            "         T_Waybill_Head_Qdc.logi_ente_code\n" +
            "     and T_Waybill_List_Qdc.waybill_Id =\n" +
            "         T_Waybill_Head_Qdc.waybill_Id WHERE ${condition}) A" +
            "         WHERE ROWNUM <= #{end})" +
            " WHERE RN >= #{start}")
    List<LogisticsOrderQdc> queryOrderEqList(@Param("start") int start, @Param("end") int end,
                                             @Param("condition") String condition);
}
